package com.kingyun.gpsinspection.purificationservice.services.som.innerservice.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.kingyun.gpsinspection.purificationservice.dao.mapper.som.StationInMapper;
import com.kingyun.gpsinspection.purificationservice.dao.mapper.som.StationOutMapper;
import com.kingyun.gpsinspection.purificationservice.facade.model.som.StationIn;
import com.kingyun.gpsinspection.purificationservice.facade.service.som.SomFileService;
import com.kingyun.gpsinspection.purificationservice.facade.service.som.StationInOutService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Created by yangcs on 2017/4/19.
 */
public class StationInOutServiceImpl implements StationInOutService {

    @Autowired
    private StationInMapper stationInMapper;
    @Autowired
    private StationOutMapper stationOutMapper;
    @Autowired
    private SomFileService somFileService;

    /**
     * 进出站列表数据
     *
     * @param stationIn
     * @return
     */
    @Override
    public JSONObject queryList(StationIn stationIn) {
        JSONObject jsonObject = new JSONObject();
        stationIn.setLimit(stationIn.getLimit() == null ? 10 : stationIn.getLimit());
        stationIn.setOffset(stationIn.getOffset() == null ? 0 : stationIn.getOffset());
        jsonObject.put("total", stationInMapper.queryCount(stationIn));
        jsonObject.put("rows", JSON.toJSON(stationInMapper.queryList(stationIn)));
        return jsonObject;
    }

    /**
     * 进站信息
     *
     * @param stationInId
     * @return
     */
    @Override
    public StationIn queryById(String stationInId) {
        StationIn stationIn = new StationIn();
        stationIn.setStationInId(stationInId);
        // 进站信息
        stationIn = stationInMapper.queryStationIn(stationIn);
        // 图片
        stationIn.setFileStr(JSON.toJSONString(somFileService.findByBusiness(stationInId)));
        // 出站记录
        stationIn.setStationOuts(stationOutMapper.queryByStationInId(stationInId));
        return stationIn;
    }

}
